using MediatR;
using SumerCoreDevOps.Application.Users.Commands;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Identity;

namespace SumerCoreDevOps.Application.Users.Handlers;

/// <summary>
/// 验证用户凭据命令处理器
/// </summary>
public class ValidateCredentialsCommandHandler : IRequestHandler<ValidateCredentialsCommand, User?>
{
    private readonly UserManager _userManager;

    public ValidateCredentialsCommandHandler(UserManager userManager)
    {
        _userManager = userManager;
    }

    public async Task<User?> Handle(ValidateCredentialsCommand request, CancellationToken cancellationToken)
    {
        return await _userManager.ValidateCredentialsAsync(
            request.Username,
            request.Password,
            request.IpAddress
        );
    }
}
